package com.briercliffe.settlers.core.domain;

/**
 * User: briercliffe
 * Date: 10/21/13
 */
public enum TileType
{
    EMPTY("X",        ResourceType.BLANK,  false   ),
    WATER("W",        ResourceType.WATER,  false   ),
    DESERT("D",       ResourceType.DESERT, false   ),
    PORT_3to1("P3",   ResourceType.WATER,  true    ),
    PORT_GRAIN("PG",  ResourceType.WATER,  true    ),
    PORT_WOOL("PW",   ResourceType.WATER,  true    ),
    PORT_ORE("PO",    ResourceType.WATER,  true    ),
    PORT_LUMBER("PL", ResourceType.WATER,  true    ),
    PORT_BRICK("PB",  ResourceType.WATER,  true    ),
    GRAIN("G",        ResourceType.GRAIN,  false   ),
    SHEEP("S",        ResourceType.SHEEP,  false   ),
    ORE("O",          ResourceType.ORE,    false   ),
    LUMBER("L",       ResourceType.LUMBER, false   ),
    BRICK("B",        ResourceType.BRICK,  false   );

    private String mKey;
    private ResourceType mResourceType;
    private boolean mPort;

    private TileType(final String iKey,
                     final ResourceType iResourceType,
                     final boolean iPort)
    {
        mKey = iKey;
        mResourceType = iResourceType;
        mPort = iPort;
    }

    public static TileType getFromKey(final String iKey)
    {
        for (TileType tileType : TileType.values())
        {
            if (tileType.getKey().equals(iKey))
            {
                return tileType;
            }
        }
        return EMPTY;
    }

    public String getKey()
    {
        return mKey;
    }

    public ResourceType getResourceType()
    {
        return mResourceType;
    }

    public boolean isPort()
    {
        return mPort;
    }

    public Port.PortType getPortType()
    {
        switch(mKey)
        {
            case "P3":
                return Port.PortType.THREE_TO_ONE;
            case "PB":
                return Port.PortType.BRICK;
            case "PO":
                return Port.PortType.ORE;
            case "PL":
                return Port.PortType.LUMBER;
            case "PG":
                return Port.PortType.GRAIN;
            case "PW":
                return Port.PortType.WOOL;
            default:
                return Port.PortType.THREE_TO_ONE;
        }
    }
}
